<template>
  <svg class="svg-icon" :style="getStyle" aria-hidden="true">
    <use :xlink:href="iconName" />
  </svg>
</template>

<script setup lang="ts">
import { computed } from 'vue'

const props = defineProps({
  name: {
    type: String,
    required: true
  },
  size: {
    type: Number,
    default: 16
  },
  color: {
    type: String,
    default: ''
  }
})
const getStyle = computed(() => {
  const { size } = props
  let s = `${size}`
  s = `${s.replace('px', '')}px`
  return {
    color: props.color,
    width: s,
    height: s
  }
})

const iconName = computed(() => {
  return `icon-${props.name}`
})
</script>

<style lang="less" scoped>
.svg-icon {
  display: inline-block;
  overflow: hidden;
  vertical-align: -0.15em;
  fill: currentColor;
}
</style>
